#include "warninfo.h"
#include<QtSql>
#include <string>
#include<iostream>
#include"dbutil.h"
using namespace std;
Warninfo ::Warninfo(QObject *parent):
    QObject(parent)
{}
void Warninfo::updateWarnInfo(QString name,QString superhigh,
                              QString high,QString low,QString superlow,
                              QString dead,QString decline,
                              QString increase
                              )
{
    Dbutil db;
    QSqlDatabase data;
    data=db.connect();
    QSqlQuery update;
    string gasname=name.toStdString();
    string shigh=superhigh.toStdString();
    string h=high.toStdString();
    string l=low.toStdString();
    string slow=superlow.toStdString();
    string d=dead.toStdString();
    string dec=decline.toStdString();
    string incre=increase.toStdString();
    string sql = "UPDATE  warninginfo set superhigh_warn="+shigh+
            ",high_warn="+h+",low_warn="+l+",superlow_warn="
            +slow+",dead_zone="+d+",decline_warn="+dec+
            ",increase_warn="+incre+" where gasname='"+gasname+"'";
    const char *k = sql.c_str();
     bool success = update.exec(k);
    if(success)  {

         qDebug()<<"upadte success";
    }
    else qDebug()<< "fail";
    db.dbclose(data);
}

void Warninfo::selectWarnInfobyName(QString gasname)
{
    Dbutil db;
    QSqlDatabase data;
    data=db.connect();
    QSqlQuery query;
    string name=gasname.toStdString();
    string sql="select *from warninginfo where gasname='"+name+"'";
    const char *k = sql.c_str();
    bool success = query.exec(k);
    if(success)  {
       query.next();
//         while(query.next()) qDebug()<<query.value().toString();
        superhigh_warn=query.value(2).toString();
        high_warn=query.value(3).toString();
        low_warn=query.value(4).toString();
        superlow_warn=query.value(5).toString();
        dead_zone=query.value(6).toString();
        decline_warn=query.value(7).toString();
        increase_warn=query.value(8).toString();
    }
    else qDebug()<< "fail";
    db.dbclose(data);
}
QString Warninfo::getsuperhigh_warn(void){
    return superhigh_warn;
}
QString Warninfo::getdead_zone(){
    return dead_zone;
}
QString Warninfo::getdecline_warn(){
    return decline_warn;
}
QString Warninfo::gethigh_warn(){
    return high_warn;
}
QString Warninfo::getincrease_warn(){
    return increase_warn;
}
QString Warninfo::getlow_warn(){
    return low_warn;
}
QString Warninfo::getsuperlow_warn(){
    return superlow_warn;
}

